using Microsoft.AspNetCore.Mvc;
using ZR.Model.FacManage.Dto;
using ZR.Model.FacManage;
using ZR.Service.FacManage.IFacManageService;
using ZR.Admin.WebApi.Filters;
using ZR.Service.FacManage;

//创建时间：2025-03-30
namespace ZR.Admin.WebApi.Controllers.FacManage
{
    /// <summary>
    /// 产线管理
    /// </summary>
    [Verify]
    [Route("FacManage/FacLine")]
    public class FacLineController : BaseController
    {
        /// <summary>
        /// 产线管理接口
        /// </summary>
        private readonly IFacLineService _FacLineService;

        public FacLineController(IFacLineService FacLineService)
        {
            _FacLineService = FacLineService;
        }

        /// <summary>
        /// 查询产线管理列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "fac:line:list")]
        public IActionResult PageFacLine([FromQuery] FacLineQueryDto parm)
        {
            var response = _FacLineService.GetPageList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 获取产线树信息
        /// </summary>
        /// <param name="disabledFactory">禁用工厂选择</param>
        /// <param name="disabledWorkshop">禁用车间选择</param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "fac:line:list")]
        public IActionResult TreeFacLine(bool disabledFactory, bool disabledWorkshop)
        {
            var response = _FacLineService.GetTreeList(disabledFactory, disabledWorkshop);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询产线管理详情
        /// </summary>
        /// <param name="LineId"></param>
        /// <returns></returns>
        [HttpGet("{LineId}")]
        [ActionPermissionFilter(Permission = "fac:line:query")]
        public IActionResult GetFacLine(string LineId)
        {
            var response = _FacLineService.GetInfo(LineId);
            
            var info = response.Adapt<FacLineDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加产线管理
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "fac:line:add")]
        [Log(Title = "产线管理", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFacLine([FromBody] FacLineDto parm)
        {
            var modal = parm.Adapt<FacLine>().ToCreate(HttpContext);

            var response = _FacLineService.AddFacLine(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新产线管理
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "fac:line:edit")]
        [Log(Title = "产线管理", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFacLine([FromBody] FacLineDto parm)
        {
            var modal = parm.Adapt<FacLine>().ToUpdate(HttpContext);
            var response = _FacLineService.UpdateFacLine(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除产线管理
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "fac:line:delete")]
        [Log(Title = "产线管理", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFacLine([FromBody] string[] ids)
        {
            var response = _FacLineService.DeleteFacLine(ids);
            return ToResponse(response);
        }

    }
}